// $codepro.audit.disable numericLiterals
//disabled numeric literals for this file because arrays must be made up of integers. 
/**
 * This file was created by Julia Deeb for use in SpaceTrader
 */
import java.io.Serializable;
import java.util.Arrays;

/**
 * This class represents a resource-item that can be found on a planet. These
 * resources can be bought and sold by the player of the game.
 * 
 * @author Julia Deeb
 * @version 1.0
 * 
 */
public class Resource implements Serializable {
    /**
     * This array represents all the possible types of resources a planet can
     * have
     */
    private final String[] types = { "Water", "Furs", "Food", "Ore", "Games",
	    "Firearms", "Medicine", "Machines", "Narcotics", "Robots" };

    /**
     * This array represents the base price each resource starts out with
     */
    private final int[] basePrice = { 30, 250, 100, 350, 250, 1250, 650, 900,
	    3500, 5000 };

    /**
     * This array represents the maximum variance a price can fluxuate by
     */
    private final int[] maxVariance = { 4, 10, 5, 10, 5, 100, 10, 5, 150, 100 };

    /**
     * This array represents the minimum numeric tech level required for a
     * planet to have this item
     */
    private final int[] minTechLevel = { 0, 0, 1, 2, 3, 3, 4, 4, 5, 6 };

    /**
     * This array represents the Price increase per tech level associated with
     * each resource
     */
    private final int[] ipl = { 3, 10, 5, 20, -10, -75, -20, -30, -125, -150 };

    /**
     * this array represents the conditions of the planet that causes the
     * resource price to spike if this condition is also present on the planet
     */
    private final String[] priceSpike = { "DESERT", "LIFELESS", "POORSOIL",
	    "MINERALPOOR", "", "", "", "", "", "" };

    /**
     * this array represents the conditions of the planet that causes the
     * resource price to drop if this condition is also present on the planet
     */
    private final String[] priceDrop = { "LOTSOFWATER", "RICHFAUNA",
	    "RICHSOIL", "MINERALRICH", "ARTISTIC", "WARLIKE", "LOTSOFHERBS",
	    "", "WEIRDMUSHROOMS", "" };

    /**
     * This array represents the favored tech level for each item that causes
     * the item to occur more frequently on the planet
     */
    private final int[] favoredTechLevel = { 2, 0, 1, 3, 6, 5, 6, 5, 5, 7 };
    
    /**
     * This value represents the mulitiplicity of the item
     */
    private int multiplicity = 0;
    
    /**
     * This value represents the numerical value of the item, and is the index of arrays 
     */
    private final int index;
    
    /**
     * This represents the price of the item as determined by the planet 
     */
    private int finalPrice;

    /**
     * Creates a new Resource with a given index, which determines its
     * properties.
     * 
     * @param index
     *            The internal number that determines the resource's properties.
     */
    public Resource(int index) {
	if (index < this.types.length) {
	    this.index = index;
	} else {
	    this.index = 0; // default to water
	}
    }

    /**
     * Used to get the favored tech level for a given resource, aka the tech
     * level in which the resource is likely to be found.
     * 
     * @return The favored tech level where the resource can be found.
     */
    public int favoredTechLevel() {
	return this.favoredTechLevel[this.index];
    }

    /**
     * Increases the prices.
     * 
     * @return A string of the event that increased the price.
     */
    public String incPrice() {
	return this.priceSpike[this.index];
    }

    /**
     * Decrease the prices.
     * 
     * @return A string of the event that decreased the price.
     */
    public String decPrice() {
	return this.priceDrop[this.index];
    }

    /**
     * Used to get the ipl for this resource.
     * 
     * @return the ipl of this resource.
     */
    public int getIPL() {
	return this.ipl[this.index];
    }

    /**
     * Used to get the minimum tech Level where this resource can be found.
     * 
     * @return Minimum tech Level for the resource.
     */
    public int getMinTechLevel() {
	return this.minTechLevel[this.index];
    }

    /**
     * Used to get the price of the resource.
     * 
     * @return Price of the resource.
     */
    public int getPrice() {
	return this.finalPrice;
    }

    /**
     * Used to set the price of this resource.
     * 
     * @param price
     *            The price to be set on this resource.
     */
    public void setPrice(int price) {
	this.finalPrice = price;
    }

    /**
     * Used to get the name of the resource.
     * 
     * @return The name of the resource.
     */
    public String getName() {
	return this.types[this.index];
    }

    /**
     * Used to get the base (unweighted by the planet) price of the resource.
     * 
     * @return The base price of the resource.
     */
    public int getBasePrice() {
	return this.basePrice[this.index];
    }

    /**
     * Used to get the maximum variance for the prices.
     * 
     * @return Maximum Variance for this item.
     */
    public int getMaxVariance() {
	return this.maxVariance[this.index];
    }

    /**
     * Used to set the number of this Resource that is available. Used in
     * markets.
     * 
     * @param num
     *            The number of this resource that is available.
     */
    public void setMultiplicity(int num) {
	this.multiplicity = num;
    }

    /**
     * Used to get the number of this Resource that is available. Used in
     * markets.
     * 
     * @return The multiplicity of this resource.
     */
    public int getMultiplicity() {
	return this.multiplicity;
    }

    /**
     * Used to get the types of resources based on the planet's tech levels.
     * 
     * @param planetTechLevel
     *            A planet's tech level.
     * @return A String of all the types of resources that are available.
     */
    public String[] getTypes(int planetTechLevel) {
	int index = 0;
	if (planetTechLevel > 6) {
	    return this.types;
	}
	for (int i = 0; i < this.minTechLevel.length; i++) {
	    if (this.minTechLevel[i] == planetTechLevel) {
		index = i;
	    }
	}
	return Arrays.copyOfRange(this.types, 0, index);
    }

    /**
     * Used to get the index, the internal number representation, of the
     * resource.
     * 
     * @return The index of the item.
     */
    public int getIndex() {
	return index;
    }

    /**
     * This method returns a string representing the resource class
     * 
     * @return a String representing the resource class
     */
    public String toString() {
	return this.toString();
    }
}
